var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgBase: app.globalData.imgUrl,          // 线上图片
    localImg: app.globalData.staticimgUrl,  // 本地图片
    info: '',       
    beautyId: '',   // 美丽币id
    top: [],        // 图标随机排布
    left: [],       // 图标随机排布
    coin: '',
    beautyprice: '',
    num: '',        //钻石图标数据
    pageNum:1,
    pageSize:10,
    count:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    app.showLoading();
    this.getList();
  },
  //美丽币数值，列表获取
  getList() {
    var that = this;
    const { pageNum, pageSize} = this.data;
    const param = {
      userId: wx.getStorageSync('userid'),
      pageNum,
      pageSize
    };
    app.request({
      url: 'doctor/beautyCoin/getbeautyCoinByUser',
      data: param,
      success: function (res) {
        wx.hideLoading();
        that.setData({
          info: res.data.UserAccount,
          coin: res.data.currUser.beautyCoin,
          num: res.data.beautyList,
          count: res.page.count
        })
        that.iconPostion();
      },
      fail: function (res) {
        // app.requestFail(res);
      }
    });
  },
  // 图标的随机布局
  iconPostion() {
    const item = this.data.num;
    let top = [];
    let left = [];
    for (let i = 0; i < item.length; i++) {
      top[i] = Math.round(Math.random() * 70);
      left[i] = Math.round(Math.random() * 75);
    }
    this.setData({
      top,
      left
    })
  },
  // 收获美丽币
  getCoin(e) {
    const that = this;
    const userId = e.currentTarget.dataset.userid;
    const beautyId = e.currentTarget.dataset.beautyid;
    const beautyprice = e.currentTarget.dataset.beautyprice;
    const param = {
      userId: userId,
      beautyId: beautyId
    };
    app.request({
      url: 'doctor/beautyCoin/updateBeauty',
      data: param,
      success: function (res) {
        that.getList()
        app.showModal("获取" + beautyprice + "美丽币");
      },
      fail: function (res) {
        // app.requestFail(res);
      }
    });
  },
  /**
 * 页面上拉触底事件的处理函数
 */
  bottomAdd: function (e) {
    const { count, pageSize, info} = this.data; 
    app.showLoading();
    this.setData({
      pageSize: pageSize + 10
    })
    if (info.length == count) {
      wx.showToast({
        title: '没有更多了哦~',
        icon: 'none',
        duration: 1000
      });
    } else {
      this.getList();
    }

  },
})